﻿function ConfirmLoadHandler() 
{
    window.clientConfirm = function(ajaxManId, text, mozEvent, oWidth, oHeight, thecallerObj, oTitle) 
    {
        var ev  = mozEvent ? mozEvent : window.event; //Moz support requires passing the event argument manually   
        ev.cancelBubble = true;
        ev.returnValue = false;
        if (ev.stopPropagation) ev.stopPropagation();
        if (ev.preventDefault) ev.preventDefault();

        var callerObj = thecallerObj;
        if (callerObj == null)
            callerObj = ev.srcElement ? ev.srcElement : ev.target;
        // for ModuleButtons: click is on the contained image, event is triggered by the parent anchor so we must get it to have url Ok
        if (callerObj.tagName == "IMG")
            callerObj = callerObj.parentNode;
        //Call radconfirm and pass it all necessary parameters
        if (callerObj) 
        {
            var callBackFn = function(arg) 
            {
                if (arg) 
                {
                    if (callerObj["type"] == 'button') 
                    {
                        var ajaxManager = $find(ajaxManId);
                        ajaxManager.ajaxRequestWithTarget(callerObj.name, '');
                    }
                    else 
                    {
                        callerObj["onclick"] = "";
                        if (callerObj.click) 
                            callerObj.click(); //Works fine every time in IE, but does not work for links in Moz   
                        else if (callerObj.tagName == "A") //We assume it is a link button!   
                        {
                            try 
                            {
                                eval(callerObj.href)
                            }
                            catch (e) { }
                        }
                    }
                }
            }
            radconfirm(text, callBackFn, oWidth, oHeight, callerObj, oTitle);
        }
        return false;
    } 
}
